#include<stdio.h>
int main() {
	int data[101], right[101];
	int t,len,i;
	scanf("%d", &t);
	for (i = 1; i <= t; i++) scanf("%d", &data[i]);
	for (i = 1; i <t; i++) right[i] = i + 1;
	right[t] = 0;
	len = t;
	len++;
	scanf("%d", &data[len]);
	int x = 1;
	while (x != 0) {
		if (data[right[x]]> data[len] && data[x] < data[len]) {
			right[len] = right[x];
			right[x] = len;
			break;
		}
		x = right[x];
	}
	x=1;
	while (x!= 0) {
		printf("%d ", data[x]);
		x= right[x];
	}
	return 0;
}
